package cn.youqu.happy.module.youqu.dal.mysql.userArrange;

import cn.youqu.happy.framework.common.pojo.PageResult;
import cn.youqu.happy.framework.mybatis.core.mapper.BaseMapperX;
import cn.youqu.happy.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.youqu.happy.module.youqu.controller.admin.userArrange.vo.UserArrangeExportReqVO;
import cn.youqu.happy.module.youqu.controller.admin.userArrange.vo.UserArrangePageReqVO;
import cn.youqu.happy.module.youqu.dal.dataobject.userArrange.UserArrangeDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 用户计划 Mapper
 *
 * @author 王其岩 20112001045
 */
@Mapper
public interface UserArrangeMapper extends BaseMapperX<UserArrangeDO> {
    UserArrangeDO findOneByIdAndUid(@Param("id") Integer id, @Param("uid") Long uid);

    UserArrangeDO findOneByActivityIdAndUid(@Param("activityId") Integer activityId, @Param("uid") Long uid);

    UserArrangeDO findOneByActivityId(@Param("activityId") Integer activityId);


    default PageResult<UserArrangeDO> selectPage(UserArrangePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<UserArrangeDO>()
                .eqIfPresent(UserArrangeDO::getUid, reqVO.getUid())
                .eqIfPresent(UserArrangeDO::getPartners, reqVO.getPartners())
                .likeIfPresent(UserArrangeDO::getActivityName, reqVO.getActivityName())
                .eqIfPresent(UserArrangeDO::getActivityId, reqVO.getActivityId())
                .betweenIfPresent(UserArrangeDO::getStartDate, reqVO.getBeginStartDate(), reqVO.getEndStartDate())
                .eqIfPresent(UserArrangeDO::getArrangeStatus, reqVO.getArrangeStatus())
                .betweenIfPresent(UserArrangeDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(UserArrangeDO::getRemark, reqVO.getRemark())
                .orderByDesc(UserArrangeDO::getId));
    }

    default List<UserArrangeDO> selectList(UserArrangeExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<UserArrangeDO>()
                .eqIfPresent(UserArrangeDO::getUid, reqVO.getUid())
                .eqIfPresent(UserArrangeDO::getPartners, reqVO.getPartners())
                .likeIfPresent(UserArrangeDO::getActivityName, reqVO.getActivityName())
                .eqIfPresent(UserArrangeDO::getActivityId, reqVO.getActivityId())
                .betweenIfPresent(UserArrangeDO::getStartDate, reqVO.getBeginStartDate(), reqVO.getEndStartDate())
                .eqIfPresent(UserArrangeDO::getArrangeStatus, reqVO.getArrangeStatus())
                .betweenIfPresent(UserArrangeDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(UserArrangeDO::getRemark, reqVO.getRemark())
                .orderByDesc(UserArrangeDO::getId));
    }

}
